package com.cimp.dao.c2;

import com.cimp.domain.c2.Distribute;
import com.cimp.domain.c2.DistributeMsg;
import com.cimp.domain.c2.SoapConfig;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * [简要描述]:
 * [详细描述]:
 *
 * @author huojinhao
 * @date 2018/11/23
 */

public interface UpstreamDao {

    @Insert("insert into t_c2_soapconfig (url,cmdFileUrl,cspid,lspid) " +
            "values(#{url},#{cmdFileUrl},#{cspid},#{lspid})")
    void insertSoapConfig(SoapConfig soapConfig);

    @Update("update t_c2_soapconfig set url=#{url},cmdFileUrl=#{cmdFileUrl},cspid=#{cspid},lspid=#{lspid} where id=#{id}")
    void updateSoapConfig(SoapConfig soapConfig);

    @Select("select * from t_c2_soapconfig order by id desc")
    List<SoapConfig> listSoapConfig();

    @Delete("delete from t_c2_soapconfig where id=#{id}")
    void deleteSoapConfig(Integer id);

    @Insert("insert into t_c2_distribute (correlateId,configId,state,create_time) " +
            "values (#{correlateId},#{configId},#{state},#{createTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insertDistribute(Distribute distribute);

    @Update("update t_c2_distribute set state=#{state} where id=#{id}")
    void updateDistributeState(@Param("id") Integer id,@Param("state") String state);

    @Update("update t_c2_distribute set state=#{state} where correlateId=#{correlateId}")
    void updateDistributeStateByCorrelateId(@Param("correlateId") String correlateId,@Param("state") String state);

    @Select(" SELECT t1.id,t1.correlateId,t1.state,t2.`cmdFileUrl`,t2.`cspid`,t2.`lspid`,t2.`url`,t1.`create_time` " +
            "FROM t_c2_distribute t1 JOIN t_c2_soapconfig t2 ON t1.configId=t2.id ORDER BY t1.id DESC limit 50")
    List<DistributeMsg> listDistributeMsg();

    @Delete("delete from t_c2_distribute where configId=#{configId}")
    void deleteDistributeByConfigId(@Param("configId") Integer configId);

}
